﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Demo.Demos.ComplexDataStructures
{
    [Serializable]
    public class ComplexDataStructuresViewModel
    {
        public PersonViewModel RootPerson { get; set; }

        public PersonViewModel SelectedPerson { get; set; }

        // coefficients
        public float LevelFactor { get; set; }
        public float FriendFactor { get; set; }
        public float OneSideFriendFactor { get; set; }

        public int ShowTop { get; set; }

        public bool IsPersonSelected
        {
            get 
            {
                return SelectedPerson != null;
            }
        }

        public IEnumerable<PersonViewModel> MostPowerfulPersons
        {
            get
            {
                List<PersonViewModel> allPersons = new List<PersonViewModel>();
                
                RootPerson.Visitor((i) => allPersons.Add(i));

                Dictionary<PersonViewModel, float> weightFactorQuick = new Dictionary<PersonViewModel, float>();
                foreach (PersonViewModel person in allPersons)
                {
                    weightFactorQuick[person] = person.PowerFactor;
                }

                return allPersons.OrderByDescending(i => weightFactorQuick[i]).Take(ShowTop);
            }
        }
    }
}